package com.css.zfzx.sjcj.modules.fxpc.HddcA1Material.service.impl;

import com.css.zfzx.sjcj.common.MenuInfoEnum;
import com.css.zfzx.sjcj.common.division.service.MyDivisionService;
import com.css.zfzx.sjcj.common.utils.StrUtils;
import com.css.zfzx.sjcj.modules.fxpc.HddcA1Material.repository.HddcA1MaterialNativeRepository;

import com.css.zfzx.sjcj.modules.fxpc.fxqhHdc100.repository.FxqhHdc100NativeRepository;
import com.css.zfzx.sjcj.modules.fxpc.fxqhPriority.repository.FxqhPriorityNativeRepository;
import com.css.zfzx.sjcj.modules.fxpc.qhDrill.repository.QhDrillNativeRepository;
import com.css.zfzx.sjcj.modules.pojo.DivisionData;
import com.css.zfzx.sjcj.modules.pojo.QueryVo;
import com.css.zfzx.sjcj.modules.pojo.RequestParams;
import com.css.zfzx.sjcj.modules.pojo.RespondParams;
import com.css.zfzx.sjcj.modules.service.CommonInterfaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("hddcA1MaterialServiceImpl")
public class HddcA1MaterialServiceImpl implements CommonInterfaceService {
    @Autowired
    private HddcA1MaterialNativeRepository nativeRepository;

    @Autowired
    private MyDivisionService myDivisionService;

    @Override
    public RespondParams dataStatistics(RequestParams params) {
        RespondParams respondParams = new RespondParams();

        List<String> menuIds = params.getMenuIds();
        MenuInfoEnum menuInfoEnum = MenuInfoEnum.HDDC_A1_IRHMATERIAL;
        boolean isHave = StrUtils.splitMenuId(menuIds, menuInfoEnum);
        if (!isHave){
            return null;
        }
        List<DivisionData> divisionDatas = new ArrayList<>();
        List<String> divisions = params.getDivision();
        for (String division : divisions) {
            DivisionData divisionData = new DivisionData();
            QueryVo queryVo = myDivisionService.getDivisionName(division);
            divisionData.setDivision(queryVo.getDivisions());


            String startTime = params.getStartTime().toString();
            String endTime = params.getEndTime().toString();
            queryVo.setStartTime(startTime);
            queryVo.setEndTime(endTime);
            String dataType = params.getDataType();
            String collectionCount = "";
            String qualityCount = "";
            if ("0".equals(dataType)){
                queryVo.setIsQuality(false);
                // 采集数量
                collectionCount = nativeRepository.count(queryVo);
            }else if ("1".equals(dataType)){
                queryVo.setIsQuality(true);
                // 质检数量
                qualityCount = nativeRepository.count(queryVo);
            }
            divisionData.setQualityCount(qualityCount);
            divisionData.setCollectionCount(collectionCount);
            divisionDatas.add(divisionData);
        }
        respondParams.setDivisionDataList(divisionDatas);
        respondParams.setMenuId(menuInfoEnum.getMenuId());
        return respondParams;
    }
}
